package com.googlecode.jascii;

import javax.script.Invocable;
import javax.script.ScriptException;

public class TdShellResult extends TdResult {

	private String shell;
	private String outpattern;
	private Object[] shellargs;
	public TdShellResult(String value, int defaultLength, int style) {
		super("", defaultLength, style);
		this.outpattern = value;
	}

	public TdShellResult(String value, int defaultLength, int style,
			boolean notTrim) {
		super(value, defaultLength, style, notTrim);
		this.outpattern = value;
	}

	public TdShellResult(String value, int defaultLength, int style,
			String defaultStr) {
		super(value, defaultLength, style, defaultStr);
		this.outpattern = value;		
	}
    
	public TdShellResult appendSellFunction( String shell )
	{
		this.shell = shell;
		return this;
	} 
	public TdShellResult appendSellArgs( Object... shellargs )
	{
		this.shellargs = shellargs;
		return this;
	} 
	


	/**
	 * @param args
	 */
	public static void main(String[] args) {
 		
		TrResult tr = new TrResult().append(new TdResult("這是測試",12,TdResult.TD_STYLE_RIGHT)).append(new TdShellResult("",20,TdShellResult.TD_STYLE_RIGHT | TdShellResult.TD_SCRIPT_TYPE).appendSellFunction("nextPageNum").appendSellArgs("第%4d頁"));
		PageResult page = new PageResult();
		page.appendHeader(tr);
		page.append(tr, true);
		page.invokingFunction("setPageNum", 20);
		System.out.println(page);
	}


	public void invokingFunction(Invocable invocableEngine) {
	   try {
		super.value =  (String)invocableEngine.invokeFunction(shell, shellargs);
	} catch (ScriptException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (NoSuchMethodException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
		
	
	}

}
